﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using AutoPartsSearch.Domain.Abstract;
using AutoPartsSearch.Domain.Common;
using Griffin.MvcContrib.SqlServer.Localization;

namespace AutoPartsSearch.Web.Infrastructure.Cache.Localizations
{
    public class LocalizedTypeRepository : SqlLocalizedTypesRepository
    {
        private readonly int _timeToHoldCache = 5;

        public LocalizedTypeRepository(ILocalizationDbContext db, IConfigurationGetter configurationGetter)
            : base(db)
        {
            int value;
            if (int.TryParse(configurationGetter.GetConfigurationValue(Constants.LocalizationCacheInMinutes), out value))
            {
                this._timeToHoldCache = value;
            }
        }

        public override Griffin.MvcContrib.Localization.Types.TypePrompt GetPrompt(System.Globalization.CultureInfo culture, Griffin.MvcContrib.Localization.Types.TypePromptKey key)
        {
            return CacheExecutor.Execute(() => base.GetPrompt(culture, key), _timeToHoldCache, culture.LCID,
                                         key.ToString());
        }

        //public override IEnumerable<Griffin.MvcContrib.Localization.Types.TypePrompt> GetPrompts(System.Globalization.CultureInfo cultureInfo, System.Globalization.CultureInfo defaultCulture, Griffin.MvcContrib.Localization.SearchFilter filter)
        //{
        //    return CacheExecutor.Execute(() => GetPrompts(cultureInfo, defaultCulture, filter), 
        //        _timeToHoldCache, cultureInfo.LCID, defaultCulture.LCID, filter.TextFilter, filter.Path);
        //}
    }
}